﻿package app.view.components.sections.expo 
{
	import app.model.RemoteProxy;
	import app.view.components.buttons.GlamurBtnBase;
	import app.view.components.guiDima.slideShowD.Image;
	import app.view.components.guiDima.switchContent.SwitchContentTextDBase;
	import app.view.components.header.HeadMarkerBase;
	import app.view.components.sections.LabeledSectionBase;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	import app.view.events.UIEvent;
	import app.view.events.UIEvent;
	import app.model.types.SectionType;
	import app.model.vo.SectionVO;
	
	/**
	 * ...
	 * @author Dmitryi_Koruagin, icq:585466579, dmitryikoruagin@yandex.ru
	 */
	public class ExpoConceptArhitecturaDBase extends LabeledSectionBase
	{
		// app.view.components.sections.expo.ExpoConceptArhitecturaDBase
		
		public var scenographia_Btn:GlamurBtnBase;
		
		public var boxSwitch:SwitchContentTextDBase
		
		public var slider:Sprite;
		public var bgdImage_1:Sprite;
		public var bgdImage_2:Sprite;
		public var bgdImage_3:Sprite;
		public var bgdImage_4:Sprite;
		public var bgdImage_5:Sprite;
		private var _slider:Image;
		private var _image1:Image;
		private var _image2:Image;
		private var _image3:Image;
		private var _image4:Image;
		private var _image5:Image;
		private var _imageArray:Array;
		
		//	CONSTRUCTOR
		public function ExpoConceptArhitecturaDBase() 
		{
			super();
		}
		
		override protected function init():void
		{
			super.init();
			
			
			// для области справа (тупо лень делать по другому)
			_slider = new Image(slider.width, slider.height, Image.RESIZE_MAX, Image.ALIGN_CENTER);
			addChild(_slider);
			_slider.x = slider.x;
			_slider.y = slider.y;
			addChild(slider);
			
			_image1 = new Image(bgdImage_1.width, bgdImage_1.height, Image.RESIZE_MAX, Image.ALIGN_CENTER);
			addChild(_image1);
			_image1.x = bgdImage_1.x;
			_image1.y = bgdImage_1.y;
			addChild(bgdImage_1);
			
			_image2 = new Image(bgdImage_2.width, bgdImage_2.height, Image.RESIZE_MAX, Image.ALIGN_CENTER);
			addChild(_image2);
			_image2.x = bgdImage_2.x;
			_image2.y = bgdImage_2.y;
			addChild(bgdImage_2);
			
			_image3 = new Image(bgdImage_3.width, bgdImage_3.height, Image.RESIZE_MAX, Image.ALIGN_CENTER);
			addChild(_image3);
			_image3.x = bgdImage_3.x;
			_image3.y = bgdImage_3.y;
			addChild(bgdImage_3);
			
			_image4 = new Image(bgdImage_4.width, bgdImage_4.height, Image.RESIZE_MAX, Image.ALIGN_CENTER);
			addChild(_image4);
			_image4.x = bgdImage_4.x;
			_image4.y = bgdImage_4.y;
			addChild(bgdImage_4);
			
			_image5 = new Image(bgdImage_5.width, bgdImage_5.height, Image.RESIZE_MAX, Image.ALIGN_CENTER);
			addChild(_image5);
			_image5.x = bgdImage_5.x;
			_image5.y = bgdImage_5.y;
			addChild(bgdImage_5);
			
			
		}
		
		private function setSelectedImage(ind:int=1):void
		{
			switch (ind) 
			{
				case 1:
					
					_image1.buttonMode = _image1.useHandCursor = false;
					_image2.buttonMode = _image2.useHandCursor = true;
					_image3.buttonMode = _image3.useHandCursor = true;
					_image4.buttonMode = _image4.useHandCursor = true;
					_image5.buttonMode = _image5.useHandCursor = true;
					_image1.removeEventListener(MouseEvent.CLICK, onCLickImage1);
					_image2.addEventListener(MouseEvent.CLICK, onCLickImage2);
					_image3.addEventListener(MouseEvent.CLICK, onCLickImage3);
					_image4.addEventListener(MouseEvent.CLICK, onCLickImage4);
					_image5.addEventListener(MouseEvent.CLICK, onCLickImage5);
					_slider.loadImage(_imageArray[0]);
				break;
				
				case 2:
					_image1.buttonMode = _image1.useHandCursor = true;
					_image2.buttonMode = _image2.useHandCursor = false;
					_image3.buttonMode = _image3.useHandCursor = true;
					_image4.buttonMode = _image4.useHandCursor = true;
					_image5.buttonMode = _image5.useHandCursor = true;
					_image1.addEventListener(MouseEvent.CLICK, onCLickImage1);
					_image2.removeEventListener(MouseEvent.CLICK, onCLickImage2);
					_image3.addEventListener(MouseEvent.CLICK, onCLickImage3);
					_image4.addEventListener(MouseEvent.CLICK, onCLickImage4);
					_image5.addEventListener(MouseEvent.CLICK, onCLickImage5);
					_slider.loadImage(_imageArray[1]);
				break;
				
				case 3:
					_image1.buttonMode = _image1.useHandCursor = true;
					_image2.buttonMode = _image2.useHandCursor = true;
					_image3.buttonMode = _image3.useHandCursor = false;
					_image4.buttonMode = _image4.useHandCursor = true;
					_image5.buttonMode = _image5.useHandCursor = true;
					_image1.addEventListener(MouseEvent.CLICK, onCLickImage1);
					_image2.addEventListener(MouseEvent.CLICK, onCLickImage2);
					_image3.removeEventListener(MouseEvent.CLICK, onCLickImage3);
					_image4.addEventListener(MouseEvent.CLICK, onCLickImage4);
					_image5.addEventListener(MouseEvent.CLICK, onCLickImage5);
					_slider.loadImage(_imageArray[2]);
				break;
				
				case 4:
					_image1.buttonMode = _image1.useHandCursor = true;
					_image2.buttonMode = _image2.useHandCursor = true;
					_image3.buttonMode = _image3.useHandCursor = true;
					_image4.buttonMode = _image4.useHandCursor = false;
					_image5.buttonMode = _image5.useHandCursor = true;
					_image1.addEventListener(MouseEvent.CLICK, onCLickImage1);
					_image2.addEventListener(MouseEvent.CLICK, onCLickImage2);
					_image3.addEventListener(MouseEvent.CLICK, onCLickImage3);
					_image4.removeEventListener(MouseEvent.CLICK, onCLickImage4);
					_image5.addEventListener(MouseEvent.CLICK, onCLickImage5);
					_slider.loadImage(_imageArray[3]);
				break;
				
				case 5:
					_image1.buttonMode = _image1.useHandCursor = true;
					_image2.buttonMode = _image2.useHandCursor = true;
					_image3.buttonMode = _image3.useHandCursor = true;
					_image4.buttonMode = _image4.useHandCursor = true;
					_image5.buttonMode = _image5.useHandCursor = false;
					_image1.addEventListener(MouseEvent.CLICK, onCLickImage1);
					_image2.addEventListener(MouseEvent.CLICK, onCLickImage2);
					_image3.addEventListener(MouseEvent.CLICK, onCLickImage3);
					_image4.addEventListener(MouseEvent.CLICK, onCLickImage4);
					_image5.removeEventListener(MouseEvent.CLICK, onCLickImage5);
					_slider.loadImage(_imageArray[4]);
				break;
			}
			
			
		}
		
		
		private function setEvents():void
		{
			scenographia_Btn.addEventListener(MouseEvent.CLICK, onScenografiaBtn);
		}
		
		private function removeEvents():void
		{
			scenographia_Btn.removeEventListener(MouseEvent.CLICK, onScenografiaBtn);
		}
		
		override public function onDestroy():void 
		{
			// чистим что тут есть и вызываем супера
			removeEvents();
			
			scenographia_Btn.destroy();
			
			_slider.destroy();
			removeChild(_slider);
			_image1.destroy();
			removeChild(_image1);
			_image2.destroy();
			removeChild(_image2);
			_image3.destroy();
			removeChild(_image3);
			_image4.destroy();
			removeChild(_image4);
			_image5.destroy();
			removeChild(_image5);
			
			
			super.onDestroy();
		};
		
		override public function get data():Object { return _data; };
		
		override public function set data(value:Object):void 
		{
			super.data = value;
			
			scenographia_Btn.setLang(_data.lang);
			
			setParamHead(HeadMarkerBase.BGD_RED);
			
			_imageArray = new Array();
			
			for each(var object:* in _data.data.img)
			{
				//trace('1423', RemoteProxy.DOMEN+object.image[1].image_path);
				_imageArray.push(RemoteProxy.DOMEN + object.image[1].image_path);
			}
			
			if (_imageArray.length<5) 
			{
				for (var i:int = 0; i < 5-_imageArray.length; i++) 
				{
					_imageArray.push('');
				}
			}
			
			_image1.loadImage(_imageArray[0]);
			_image2.loadImage(_imageArray[1]);
			_image3.loadImage(_imageArray[2]);
			_image4.loadImage(_imageArray[3]);
			_image5.loadImage(_imageArray[4]);
			
			var ar:Array = new Array();
			
			for each(var objectText:* in _data.data.txt)
			{
				//trace('text', objectText.text);
				ar.push({text:String(objectText.text).substr(1)});
			}
			
			boxSwitch.data = ar as Array;
			
			setSelectedImage(1);
			
			
			setEvents();
		};
		
		/**
		 * переход на сценографию
		 * @param	e
		 */
		private function onScenografiaBtn(e:MouseEvent):void 
		{
			removeEvents();
			
			var obj:SectionVO = new SectionVO();
			obj.id = SectionType.PAGE_EXPO_CONCEPT_SCENOGRAPHIA;
			obj.currentId = id;
			obj.params = null;
			
			var ev:UIEvent = new UIEvent(UIEvent.SECTION_CHANGE);
			ev.data = obj;
			dispatchEvent(ev);
		}
		
		private function onCLickImage1(e:MouseEvent):void 
		{
			setSelectedImage(1);
		}
		
		private function onCLickImage2(e:MouseEvent):void 
		{
			setSelectedImage(2);
		}
		
		private function onCLickImage3(e:MouseEvent):void 
		{
			setSelectedImage(3);
		}
		
		private function onCLickImage4(e:MouseEvent):void 
		{
			setSelectedImage(4);
		}
		
		private function onCLickImage5(e:MouseEvent):void 
		{
			setSelectedImage(5);
		}
	}

}